package o;

import androidx.annotation.NonNull;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import java.util.ArrayDeque;
import java.util.PriorityQueue;

abstract class ajp implements ajf {
    private long ʼ;
    private final ArrayDeque<ajj> ˊ;
    private c ˋ;
    private long ˎ;
    private final ArrayDeque<c> ˏ = new ArrayDeque();
    private final PriorityQueue<c> ॱ;

    final class a extends ajj {
        final /* synthetic */ ajp ˎ;

        private a(ajp o_ajp) {
            this.ˎ = o_ajp;
        }

        public final void ˋ() {
            this.ˎ.ˋ(this);
        }
    }

    static final class c extends ajl implements Comparable<c> {
        private long ˎ;

        private c() {
        }

        public /* synthetic */ int compareTo(@NonNull Object obj) {
            return ॱ((c) obj);
        }

        public int ॱ(@NonNull c cVar) {
            if (ˏ() == cVar.ˏ()) {
                long j = this.ˏ - cVar.ˏ;
                if (j == 0) {
                    j = this.ˎ - cVar.ˎ;
                    if (j == 0) {
                        return 0;
                    }
                }
                if (j <= 0) {
                    return -1;
                }
                return 1;
            } else if (ˏ()) {
                return 1;
            } else {
                return -1;
            }
        }
    }

    protected abstract aji ʻ();

    protected abstract void ˊ(ajl o_ajl);

    protected abstract boolean ˊ();

    public /* synthetic */ Object ˏ() throws Exception {
        return ʼ();
    }

    public /* synthetic */ void ˏ(Object obj) throws Exception {
        ˎ((ajl) obj);
    }

    public /* synthetic */ Object ॱ() throws Exception {
        return ʽ();
    }

    public ajp() {
        int i = 0;
        for (int i2 = 0; i2 < 10; i2++) {
            this.ˏ.add(new c());
        }
        this.ˊ = new ArrayDeque();
        while (i < 2) {
            this.ˊ.add(new a());
            i++;
        }
        this.ॱ = new PriorityQueue();
    }

    public void ˏ(long j) {
        this.ˎ = j;
    }

    public ajl ʽ() throws SubtitleDecoderException {
        amm.ˏ(this.ˋ == null);
        if (this.ˏ.isEmpty()) {
            return null;
        }
        this.ˋ = (c) this.ˏ.pollFirst();
        return this.ˋ;
    }

    public void ˎ(ajl o_ajl) throws SubtitleDecoderException {
        amm.ˊ(o_ajl == this.ˋ);
        if (o_ajl.i_()) {
            ˎ(this.ˋ);
        } else {
            c cVar = this.ˋ;
            long j = this.ʼ;
            this.ʼ = 1 + j;
            cVar.ˎ = j;
            this.ॱ.add(this.ˋ);
        }
        this.ˋ = null;
    }

    public ajj ʼ() throws SubtitleDecoderException {
        if (this.ˊ.isEmpty()) {
            return null;
        }
        while (!this.ॱ.isEmpty() && ((c) this.ॱ.peek()).ˏ <= this.ˎ) {
            c cVar = (c) this.ॱ.poll();
            if (cVar.ˏ()) {
                ajj o_ajj = (ajj) this.ˊ.pollFirst();
                o_ajj.ॱ(4);
                ˎ(cVar);
                return o_ajj;
            }
            ˊ(cVar);
            if (ˊ()) {
                aji ʻ = ʻ();
                if (!cVar.i_()) {
                    o_ajj = (ajj) this.ˊ.pollFirst();
                    o_ajj.ˎ(cVar.ˏ, ʻ, Long.MAX_VALUE);
                    ˎ(cVar);
                    return o_ajj;
                }
            }
            ˎ(cVar);
        }
        return null;
    }

    private void ˎ(c cVar) {
        cVar.ˊ();
        this.ˏ.add(cVar);
    }

    protected void ˋ(ajj o_ajj) {
        o_ajj.ˊ();
        this.ˊ.add(o_ajj);
    }

    public void ˋ() {
        this.ʼ = 0;
        this.ˎ = 0;
        while (!this.ॱ.isEmpty()) {
            ˎ((c) this.ॱ.poll());
        }
        if (this.ˋ != null) {
            ˎ(this.ˋ);
            this.ˋ = null;
        }
    }

    public void ˎ() {
    }
}
